package com.example.config;

import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.security.Keys;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Base64;

import javax.crypto.SecretKey;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;

@Configuration
public class JwtConfig {

    /**
     * 可以用来生成一个安全的密钥并在启动时输出
     */
    @Bean
    public SecretKey jwtSecretKey() {
        // 获取配置的密钥或生成一个随机密钥
        SecretKey key = Keys.secretKeyFor(SignatureAlgorithm.HS256);
        String encodedKey = Base64.getEncoder().encodeToString(key.getEncoded());
        System.out.println("Generated JWT key: " + encodedKey);
        return key;
    }
} 